package com.happy3w.cmds.command;

import com.beust.jcommander.JCommander;

import java.util.List;

public abstract class ArgAppCmd<T> implements AppCmd {
    private final Class<T> argType;

    protected ArgAppCmd(Class<T> argType) {
        this.argType = argType;
    }

    @Override
    public void run(List<String> argList) throws Exception {
        T args = argType.getConstructor().newInstance();
        JCommander commander = new JCommander(args);
        commander.parse(argList.toArray(new String[0]));

        runWithArg(args);
    }

    public abstract void runWithArg(T args) throws Exception;
}